package com.example.controller;

import com.example.common.Result;
import com.example.entity.Book;
import com.example.entity.Notice;
import com.example.entity.Params;
import com.example.service.BookService;
import com.example.service.NoticeService;
import com.github.pagehelper.PageInfo;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 日期：2025/5/11 17:55
 */

@CrossOrigin
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @PostMapping
    public Result update(@RequestBody Notice notice) {
        if(ObjectUtils.isEmpty(notice.getId())){
            noticeService.add(notice);
        }
        else{
            noticeService.update(notice);
        }
        return Result.success();
    }

    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Notice> info = noticeService.findBySearch(params);
        return Result.success(info);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        noticeService.delete(id);
        return Result.success();
    }


}
